ConfigApiJava

API for management of config files, with better compile-time friendliness for Java-only builds.

Configs can de/serialized from File, string, or raw TomlElement. File read is performed with validation and correction.

The wiki has several articles related to using and designing configs

Author

fzzyhmstrs

Since

0.1.0

Functions

Link copied to clipboard
fun <T : Any> buildTranslations(jClass: Class<T>, id: Identifier, lang: String, logWarnings: Boolean, builder: BiConsumer<String, String>)

Applies a set of translations for the provided class object to the provided builder. Uses Translatable.Name, Translatable.Desc, and Translatable.Prefix annotations to power the generation. TomlComment and Comment can be used to provide en_us description lang.

Link copied to clipboard

Provides an instance of the EventApi for registering to config events

Link copied to clipboard

Whether a config corresponding to the provided scope is registered

Returns whether a config corresponding to the provided scope has been loaded or not, on the specified load side.

Link copied to clipboard

Determines if a Config GUI is open currently.

Link copied to clipboard

Provides an instance of the NetworkApi for usage of the built-in cross-loader networking API

Link copied to clipboard
fun openScreen(scope: String)

Opens a config GUI. Does nothing on the server (But is not marked with @Environment, allowing for safe inclusion anywhere in code)

Link copied to clipboard

Provides an instance of the PlatformApi for usage of the built-in cross-loader utilities

Link copied to clipboard

overload of readOrCreateAndValidate that automatically applies the name, folder, and subfolder from the config itself. Automatically adds ".toml" to the name for reading and writing.

fun <T : Config> readOrCreateAndValidate(name: String, folder: String = "", subfolder: String = "", configClass: Supplier<T>): T

Reads a config from File or Creates a new config class; writes out any corrections, updates, or new content to File. Automatically adds ".toml" to the name for reading and writing.

Link copied to clipboard
fun <T : Config> registerAndLoadConfig(configClass: Supplier<T>, registerType: RegisterType = RegisterType.BOTH): T

Creates and registers a Config. Use this over registerConfig and readOrCreateAndValidate if possible.

Link copied to clipboard
fun <T : Config> registerAndLoadNoGuiConfig(configClass: Supplier<T>, registerType: RegisterType = RegisterType.CLIENT): T

Creates and registers a Config. Use this over registerConfig and readOrCreateAndValidate if possible.

Link copied to clipboard
fun <T : Config> registerConfig(config: T, configClass: Supplier<T>, registerType: RegisterType = RegisterType.BOTH): T

Registers a Config to registries. Does NOT load or validate it from file. Use this if you have custom initialization to perform, otherwise use registerAndLoadConfig for full initialization functionality.

Link copied to clipboard

Registers a ConfigScreenProvider to the client config registry. This provider will have priority over the default screen manager if it provides a non-null screen or successfully opens its own screen.

Link copied to clipboard

Provides an instance of the ResultApiJava for creation of ResultProvider to indirectly refer to configs via scope strings